/**  
 * @Title: DataXComp.java
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
 */  
package com.fsxgt.datagrid.component.handler.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fsxgt.datagrid.component.bo.CmpCaseBO;
import com.fsxgt.datagrid.component.bo.CmpCaseRouteBO;
import com.fsxgt.datagrid.component.service.impl.CmpExecSqlService;
import com.fsxgt.datagrid.ds.component.MybatisComponent;
import com.fsxgt.datagrid.ds.service.impl.MetaService;
import com.fsxgt.datagrid.ds.utils.ParamUtil;
import com.fsxgt.datagrid.flow.handler.FlowContext;
import com.fsxgt.datagrid.flow.handler.FlowReturn;
import com.fsxgt.datagrid.flow.handler.IComponentHandler;

import lombok.extern.slf4j.Slf4j;

/**  
 * @ClassName: DataxComponent
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-04-13 16:21:25 
*/
@Slf4j
@Component
public class CmpCaseHandler extends IComponentHandler{
	
	@Autowired
	private CmpExecSqlService cmpExecSqlService;
	@Autowired
	private MetaService metaService;
	@Autowired
	private MybatisComponent mybatisComponent;

	public FlowReturn handler(final Object config,FlowContext context) throws Exception{
		
		
		CmpCaseBO bo = (CmpCaseBO)config;
		
		List<CmpCaseRouteBO> routeList = bo.getRouteList();
		
		List<String> returnRoute=new ArrayList();
		
		
		Map params=(Map) context.get(ParamUtil.PARAM_KEY);

		for(CmpCaseRouteBO route:routeList) {
			
			Object a=params.get(route.getParam());
		
			String bparam=ParamUtil.getParamName(route.getParamValue());
			
			if(bparam!=null) {
				if(ParamUtil.compare(a,params.get(bparam), route.getRelation())) {
					returnRoute.add(route.getToComponentSeq());
				}
			}else {
				if(ParamUtil.compare(a,route.getParamValue(), route.getRelation())) {
					returnRoute.add(route.getToComponentSeq());
				}
			}
	
			
			
		}
		
		return new FlowReturn(returnRoute);


	}
	

	/**  
	 * @Title: getName
	 * @Description: TODO(描述)
	 * @return 
	 * @see com.fsxgt.datagrid.core.handler.ICommonComponentHandler#getName() 
	 * @author liuyi
	 * @date 2023-04-14 13:49:53 
	 */ 
	@Override
	public String getComponentType() {
		// TODO Auto-generated method stub
		return "Case";
	}
	




	@Override
	public void stopHandler(Object config, FlowContext context) throws Exception {
		// TODO Auto-generated method stub

	}
	
	
	
}
